package com.atguigu.jinx.controller;

import com.alipay.api.AlipayApiException;
import com.atguigu.jinx.entity.vo.IncomeAndExpenditureSituationVO;
import com.atguigu.jinx.service.IUserBalanceService;
import com.atguigu.jinx.utils.R;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Description;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 用户的账单页面
 * </p>
 *
 * @author steve
 * @since 2025-08-07
 */
@RestController
@RequestMapping("/jinx/rechargeOrder")
@RequiredArgsConstructor
public class RechargeOrderController {

    final IUserBalanceService userBalanceService;

    /**
     * 用户展示余额收支统计信息
     */
    @Description("用户展示余额收支信息")
    @GetMapping("/userDisplayBalanceIneStatistics")
    public R userDisplayBalanceIneStatistics(@RequestParam String startMonth,
                                             @RequestParam String endMonth) {
        return R.ok().put("userDisplayBalanceIneStatistics", userBalanceService.userDisplayBalanceIneStatistics(startMonth, endMonth));
    }

    /**
     * 用户展示收支清单信息
     */
    @Description("用户展示收支清单信息")
    @GetMapping("/userDisplayIneListInfo")
    public R userDisplayIneListInfo() {
        List<IncomeAndExpenditureSituationVO> value = userBalanceService.userDisplayIneListInfo();
        return R.ok().put("userDisplayIneListInfo", value);
    }

    /**
     * 用户支付宝充值
     */
    @Description("调用支付系统,用户支付宝充值")
    @GetMapping(path = "/alipayCharge", produces = "text/html")
    public String alipayCharge(@RequestParam BigDecimal amount) throws AlipayApiException {
        return userBalanceService.alipayCharge(amount);
    }

    /**
     * 用户微信充值(native_pay)
     */
    @Description("调用支付系统,用户二维码微信充值")
    @PostMapping("/wechatpayCharge")
    public R wechatpayCharge(@RequestBody BigDecimal amount) throws IOException {
        return R.ok().put("userDisplayIneListInfo", userBalanceService.wechatpayCharge(amount));
    }

    /**
     * 查单
     */
    @Description("对充值订单存在疑问,进行手动查单的功能,如果存在不一致则修改表状态,并且刷新该页面")
    @GetMapping(path = "/rechargeOrderRequest")
    public R rechargeOrderRequest(@RequestParam String orderNo) {
        boolean s = userBalanceService.rechargeOrderRequest(orderNo);
        return R.ok().put("rechargeOrderRequest", s);
    }
}
